#include "timereater.h"

TimerEater::TimerEater(std::function<void ()> func, int msec, QObject *parent)
    : QObject{parent}
    , m_func(func)
    , timer(new QTimer(parent))
{
    timer->setInterval(msec);

    connect(timer, &QTimer::timeout, this, &TimerEater::slotTimeout);
}

TimerEater::TimerEater(std::function<void ()> func, QObject *parent)
    : QObject{parent}
    , m_func(func)
    , timer(new QTimer(parent))
{
    connect(timer, &QTimer::timeout, this, &TimerEater::slotTimeout);
}

void TimerEater::start(int start_delay)
{
    if (start_delay == 0)
    {
        timer->start();
    }
    else
        timer->start(start_delay);
}

void TimerEater::slotTimeout()
{
    m_func();
}
